<template>
	<view class="confirm-content">
		<TopBar :indexflag="true" :combakflag="true" :lang="false" :bottom="true" :title="$t('ConfirmOrder')"
			:barstyle="colortopic()"></TopBar>
		<view class="" :style="{direction:i18nLocale=='ug'?'rtl':''}">
			<!-- 购物车列表 -->
			<view class="cart-list card-style">
				<view class="card-item" v-for="(item,index) in totalshop.categories" v-if="totalshop.length!=0">
					<view class="item" v-for="(sub_item,sub_index) in item.products" v-if="sub_item.qty">
						<view class="left">
							<image :src="getImgSrc(sub_item.cover)" class="img"></image>
							<view class="shop-content">
								<view class="name">{{ i18nLocale=='ug'?sub_item.ug_name:sub_item.cn_name }}</view>
								<view class="qut"> <text class="x-text">X</text> <text>{{sub_item.qty}}</text>
								</view>
							</view>
						</view>
						<view class="right">
							￥{{sub_item.price}}
						</view>
					</view>
				</view>
				<view class="all-Price">
					<view class="title">{{$t('TotalPrice')}}</view>
					<view class="price">￥ {{price}}</view>
				</view>
			</view>
			<view class="selecet-time card-style" @click="tableshow=true">
				<view class="title">{{$t('TableNumber')}}</view>
				<view class="time">
					<view class="input-item" style="padding-top: 20rpx;">
						<u--input v-model="table_num" :placeholder="$t('TableNumber')" type="number" fontSize="28rpx"
							:adjustPosition='false' @input="tableinput"></u--input>
					</view>
				</view>
			</view>
			<!-- 备注 -->
			<view class="remark">
				<view class="title">{{$t('Remark')}}</view>
				<u--textarea v-model="remark_value" maxlength="200" :placeholder="$t('RemarkPlaceholder')"
					border="none"></u--textarea>
			</view>

			<view class="bottom-button" :style="{direction:i18nLocale=='ug'?'ltr':''}">
				<view class="shre-left">
					<view class="icon-box">
						<u-icon name="shopping-cart" :color="colortopic()" size="48"></u-icon>
						<view class="number">{{totalnumber}}</view>
					</view>
					<view class="price-box">
						<view class="price">￥<text style="font-weight: bold;">{{price.toFixed(1)}}</text>
						</view>
					</view>
				</view>
				<view class="share-right" @click="Checkout">
					{{$t('GoCheckout')}}
				</view>
			</view>

		</view>
		<u-toast ref="uToast" :message="notmessage"></u-toast>
		<Loading :show="loadshow" bgColor="" iconName="circle" :text="$t('Loading')"></Loading>
	</view>
</template>

<script>
	import {
		postorders,
		wePay
	} from '@/api/employee.js';
	export default {
		data() {
			return {
				remark_value: '',
				selecetItem: [],
				alertdata: '',
				notmessage: '请仔细填写!',
				loadshow: false,
				tableshow: false,
				table_num: this.$store.state.tabelinfo.table_num
			}
		},
		onLoad(e) {
			uni.setNavigationBarTitle({
				title: this.$t('ConfirmOrder')
			})
			//获取配送费
			// this.getConfigs();
			//订单处理
			this.$store.state.shop.totalshop.categories.map(item => {
				item.products.map(sub_item => {
					if (sub_item.qty) {
						this.selecetItem.push({
							id: sub_item.id,
							qty: sub_item.qty
						});
					}
				})

			})

		},
		computed: {
			price() {
				return this.$store.state.shop.totalprice;
			},
			totalnumber() {
				return this.$store.state.shop.totalnumber;
			},
			totalshop() {
				return this.$store.state.shop.totalshop;
			},

			i18nLocale() {
				return this.$i18n.locale;
			},
			Shipment() {
				return this.$store.state.shipment;
			},

		},
		methods: {
			selecetType(index) {
				this.actype = index;
			},
			changeddress(index, item) {
				this.address_index = item.id;

				this.actvaddress = item;
				this.addressshow = false;
			},
			//订单生成微信支付
			Checkout() {
				let that = this;
				that.loadshow = true;
				if (that.selecetItem.length && that.table_num) {
					postorders({
						shop_id: that.$store.state.employeeinfo.shop_id,
						table_number: that.table_num,
						product: that.selecetItem,
						remark: that.remark_value
					}).then((res) => {
						if (res.code == 200) {
							that.loadshow = false;
							that.$store.commit('Setneworder', 1);
							that.$store.commit('clearShop');
							this.$store.commit('Settabelinfo', {
								shop_id: this.$store.state.employeeinfo.shop_id,
								table_num: ''
							});
							uni.navigateBack();

						}
					})
				} else {
					that.$refs.uToast.show({
						top: 0,
						message: this.$t('TableEmpty'),
						color: '#fff',
						bgColor: '#f0ba53'
					})
					that.loadshow = false;
					return;
				}
			},
			tableinput(e) {
				//存到store
				this.$store.commit('Settabelinfo', {
					shop_id: this.$store.state.employeeinfo.shop_id,
					table_num: e
				});
			}
		}
	}
</script>

<style lang="scss" scopd>
	.confirm-content {
		width: 100%;
		padding: 20rpx 20rpx;
		box-sizing: border-box;
		padding-bottom: 200rpx;

		.selecet-type {
			.selecet-item {
				height: 200rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-around;
				width: 48%;
				border: 4rpx solid $uni-border-color;
				border-radius: $uni-border-radius-lg;
				box-sizing: border-box;
				padding: $uni-spacing-padding-sm;
				position: relative;
				overflow: hidden;

				.title {
					font-size: $uni-font-size-base;
				}

				.sub-title {
					color: $uni-text-color-grey;
					font-size: $uni-font-size-sm1;
					padding: 10rpx 0rpx;
				}

				.price {
					font-size: $uni-font-size-lg;
					font-weight: bold;
				}

				.selecet-top {
					&:before {
						content: '';
						position: absolute;
						right: 0;
						top: 0;
						border-top-right-radius: 10rpx;
						border: 40rpx solid $uni-color-topic;
						border-bottom-color: transparent;
						border-left-color: transparent;
					}

					&:after {
						content: '';
						width: 10rpx;
						height: 25rpx;
						position: absolute;
						right: 6rpx;
						top: 3rpx;
						border: 8rpx solid #fff;
						border-top-color: transparent;
						border-left-color: transparent;
						transform: rotate(35deg);
					}




				}
			}

			.active {
				border-color: $uni-color-topic;
			}
		}

		.selecet-address {
			.title {
				color: $uni-color-title;
				font-size: $uni-font-size-base;
			}

			.address-content {
				display: flex;
				flex-direction: column;

				.user {
					display: flex;
					padding-top: 20rpx;
					color: $uni-text-color-grey;

					.pone {
						padding: 0rpx 30rpx;
					}
				}
			}
		}

		.addres-liist {
			width: 100%;
			height: 70vh;
			position: relative;

			.top-title {
				width: 100%;
				height: 100rpx;
				font-size: $uni-font-size-lg;
				color: $uni-color-title;
				background-color: #eff1f6;
				border-radius: $uni-border-radius-lg 0rpx 0rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.scroll-conetnt {
				width: 100%;
				height: calc(100% - 100rpx);

				.item {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					box-sizing: border-box;
					padding: 30rpx 20rpx;
					border-top: 2rpx solid $uni-border-color;

					.left {
						display: flex;
						align-items: center;
						width: calc(100% - 100rpx);

						.seletor {
							width: 100rpx;
							height: 100rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							padding: 20rpx;
							box-sizing: border-box;
						}

						.addres-content {
							width: calc(100% - 100rpx);
							display: flex;
							flex-direction: column;
							justify-content: space-between;
							color: $uni-color-title;
							padding: 0rpx $uni-spacing-padding-sm;
							box-sizing: border-box;

							.address {

								// display: flex;
								view {
									padding: 10rpx 0rpx;
								}
							}

							text {
								padding: 0rpx 10rpx;
							}

							.user {
								display: flex;
								color: $uni-text-color-grey;
								padding-top: 10rpx;
							}
						}

					}

					.right {
						width: 100rpx;

					}
				}
			}

			.footer-button {
				width: 92%;
				height: 100rpx;
				left: 4%;
				position: fixed;
				bottom: 2%;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 50rpx;
				background-color: $uni-color-topic;
				color: #fff;
				font-size: $uni-font-size-base;
			}
		}

		.selecet-time {
			color: $uni-color-title;
			font-size: $uni-font-size-base;

			.time {
				display: flex;
				align-items: center;


				text {
					padding: 0rpx $uni-spacing-padding-sm;
				}


			}
		}

		.cart-list {
			display: flex;
			flex-direction: column;
			width: 100%;

			.card-item {
				width: 100%;

			}

			.item {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 15rpx;

				.left {
					display: flex;
					align-items: center;

					image {
						width: 120rpx;
						height: 100rpx;
						border-radius: $uni-border-radius-sm;
					}

					.shop-content {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						padding: 0rpx 20rpx;

						.name {
							font-weight: bold;
							padding: 10rpx 0rpx;
						}

						.qut {
							font-size: $uni-font-size-base;
							color: $uni-text-color-grey;

							.x-text {
								font-size: $uni-font-size-sm0;
								padding-right: 3rpx;
							}
						}
					}

				}

				.right {
					display: flex;
					align-items: center;
					color: $uni-color-topic;
				}
			}

			.dcrtion-price {
				text-decoration: line-through;
			}

			.delivery-fees {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx 0rpx;
				border-top: 2rpx solid $uni-border-color;
				border-bottom: 2rpx solid $uni-border-color;
				margin-top: 30rpx;

				.title {
					color: $uni-color-title;
					font-size: $uni-font-size-base;
				}

				.price {
					color: $uni-text-color-grey;
					direction: ltr !important;
				}
			}

			.all-Price {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: $uni-spacing-padding-sm 0rpx;
				border-top: 2rpx solid #999;
				margin-top: 30rpx;

				.price {
					direction: ltr !important;
				}

				.title {
					color: $uni-color-title;
					font-size: $uni-font-size-base;
				}
			}
		}

		.remark {
			width: 100%;
			display: flex;
			flex-direction: column;
			background-color: $uni-bg-color-box;
			border-radius: $uni-border-radius-lg;
			padding: $uni-spacing-padding-sm;
			box-sizing: border-box;
			margin-top: 20rpx;
			box-shadow: $uni-bg-shadow;

			.title {
				color: $uni-color-title;
				font-size: $uni-font-size-base;
			}

		}

		.bottom-button {
			width: 92%;
			height: 100rpx;
			left: 4%;
			position: fixed;
			bottom: 4%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-radius: 50rpx;
			background-color: rgba(51, 51, 51, 1);

			.shre-left {
				display: flex;
				align-items: center;
				box-sizing: border-box;
				padding-left: 20rpx;

				.icon-box {
					position: relative;

					.number {
						position: absolute;
						top: 0%;
						right: 0%;
						width: 40rpx;
						height: 40rpx;
						border-radius: 100%;
						background-color: $uni-color-topic;
						color: #fff;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: $uni-font-size-sm1;
						border: 4rpx solid #333333;
					}
				}

				.price-box {
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.price {
						color: #fff;
						font-size: 36rpx;
						font-weight: 300;
					}

					.move-price {
						color: $uni-text-color-grey;
						font-size: $uni-font-size-paragraph;
					}
				}
			}

			.share-right {
				height: 100%;
				background-color: $uni-color-topic;
				border-radius: 0rpx 50rpx 50rpx 0rpx;
				color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 0rpx 60rpx;
				box-sizing: border-box;
				font-size: 38rpx;
				// font-weight: 550;
			}

		}

		.card-style {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: $uni-bg-color-box;
			border-radius: $uni-border-radius-lg;
			padding: $uni-spacing-padding-sm;
			box-sizing: border-box;
			margin-top: $uni-spacing-margin-sm;
			box-shadow: $uni-bg-shadow;
		}
	}

	.uni-textarea-compute,
	.uni-textarea-line,
	.uni-textarea-placeholder,
	.uni-textarea-textarea {
		font-size: 26rpx !important;
	}
</style>